package exp2;

import java.util.*;

public class T2_1 {
    public static void main(String[] args) {
        ArrayList<Integer> L1 = new ArrayList<>();
        ArrayList<Integer> L2 = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        System.out.print("L1: ");
        String[] str;
        str = sc.nextLine().split(",");
        for(int i = 0; i < str.length; i++) {
            L1.add(Integer.parseInt(str[i]));
        }
        System.out.print("L2: ");
        str = sc.nextLine().split(",");
        for(int i = 0; i < str.length; i++) {
            L2.add(Integer.parseInt(str[i]));
        }
        //
        long stime = System.nanoTime();
        ArrayList<Integer> L3 = new ArrayList<>();
        int j = 0, i = 0;
        while (i < L1.size() && j < L1.size()) {
            int L1temp = L1.get(i);
            if (L1temp < L2.get(j)) {
                i++;
            } else if (L1temp > L2.get(j)) {
                j++;
            } else {
                L3.add(L1temp);
                i++;
                j++;
            }
        }
        long etime = System.nanoTime();
        System.out.println(L3 + " spend: " + (etime - stime));
        //
        stime = System.nanoTime();
        L1.retainAll(L2);
        etime = System.nanoTime();
        System.out.println(L1 + " spend: " + (etime - stime));
    }
}
